import json
from django.db.utils import IntegrityError
from django.shortcuts import render
from django.http import HttpResponse, JsonResponse
from django.views import View
from . import models

# Create your views here.



class Demand(View):


    def get(self, request):

        context = {
            "page": "demand"
        }

        return render(request, 'technology_services/demand.html', context=context)

    def post(self, request):

        try:

            models.Demand.objects.create(

                raw_json = json.loads(request.body)
                
            )

        except IntegrityError as e:

            result = {
                "status": -1,
                "errorCode": 1000,
                'errorMsg': '已经提交成功！',
                "resultBody": None
            }

        else:

            result = {
                "status": 1,
                "errorCode": None,
                'errorMsg': None,
                "resultBody": "提交成功"
            }

        return JsonResponse(result)
